home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / ai.prl / mike1.exe / LIGHTS.KB < prev    next >
Encoding:
Text File  |  1990-07-12  |  3.1 KB  |  111 lines

  1. /* LIGHTS.KB
  2. Simple diagnosis of a faulty series circuit.
  3. After loading this file (using ?- kb 'lights.kb'.)
  4. you invoke the forward-chainer via
  5.      ?- fc.
  6.  
  7.  N.B. to make the demo work, you must answer
  8. that chain_of_lights1 is the problematic device.
  9. That is, when you see the prompt
  10.        Please name the problematic device==>
  11. you should type in
  12.        chain_of_lights1.
  13. BE SURE TO INCLUDE THE 'FULL STOP' (PERIOD)
  14.  */
  15.  
  16. /* Static causal model for connected devices */
  17.  
  18. chain_of_lights1 instance_of series_circuit with
  19.       components: [bulb1, bulb2, bulb3, plug1, fuse1],
  20.       last_element: bulb3.
  21.  
  22. bulb1 instance_of bulb with
  23.       comes_from: plug1,
  24.       goes_to: bulb2.
  25.  
  26. bulb2 instance_of bulb with
  27.       comes_from: bulb1,
  28.       goes_to: bulb3.
  29.  
  30. bulb3 instance_of bulb with
  31.       comes_from: bulb2.
  32.  
  33. plug1 instance_of plug with
  34.       comes_from: fuse1,
  35.       goes_to: bulb1.
  36.  
  37. fuse1 instance_of fuse with
  38.       comes_from: mains,
  39.       goes_to: plug1.
  40.  
  41. /* some explained_by clauses in case of "why." responses to queries */
  42.  
  43. ['Please name the problematic device']
  44.   explained_by
  45. ['The name of the device is used as a starting point, from which we',nl,
  46. 'look up its sub-parts and then start searching for the weak link.',nl].
  47.  
  48. ['Test ',Item,'in a known working circuit',nl,
  49.              'and then enter "ok." if it works,',nl,
  50.              'or "kaput." if it does not.']
  51.  explained_by
  52.  ['We use this information to identify the weak link in the chain.'].
  53.  
  54. /* The rules for "no chain is stronger than its weakest link" */
  55.  
  56. rule init forward
  57.      if
  58.        start
  59.      then
  60.        remove start &
  61.        query ['Please name the problematic device'] receives_answer D &
  62.        add [D,is,broken].
  63.  
  64. rule begin_chaining forward
  65.      if
  66.        [D,is,broken] &
  67.        D instance_of series_circuit &
  68.        the last_element of D is Last
  69.      then
  70.        add [follow,the,chain,from,Last].
  71.  
  72. rule continue_chaining forward
  73.      if
  74.        [follow,the,chain,from,Item] &
  75.        [Item,is,ok] &
  76.        the comes_from of Item is PreviousItem
  77.      then
  78.        remove [follow,the,chain,from,Item] &
  79.        add [follow,the,chain,from,PreviousItem].
  80.  
  81. rule dead_end forward
  82.      if
  83.        [follow,the,chain,from,Item] &
  84.        [Item,is,ok] &
  85.        -- the comes_from of Item is PreviousItem
  86.      then
  87.        announce ['Sorry, but ', Item, ' is as far back in the chain',nl,
  88.                  'as I can go.  I give up.'] &
  89.        halt.
  90.  
  91. rule ask_it forward
  92.      if
  93.        [follow,the,chain,from,Item] &
  94.        -- [Item,is,ok] &         /* not definitely ok... */
  95.        -- [Item,is,kaput]        /* not definitely kaput */
  96.      then
  97.       query ['Test ',Item,'in a known working circuit',nl,
  98.              'and then enter "ok." if it works,',nl,
  99.              'or "kaput." if it does not.']
  100.         receives_answer Ans &
  101.       add [Item,is,Ans].
  102.  
  103. rule found_culprit forward
  104.      if
  105.        [Item,is,kaput]
  106.      then
  107.        announce ['OK: ',Item,' is your source of difficulty', nl,
  108.                  'so you should replace it with a known working one.'] &
  109.        halt.
  110.  
  111.